package com.zjsru.plan2024.oneday;

/**
 * 2710. 移除字符串中的尾随零
 * @Author: cookLee
 * @Date: 2024-06-29
 */
public class RemoveTrailingZeros {

    /**
     * 主
     * \
     * 输入：num = "51230100"
     * 输出："512301"
     * 解释：整数 "51230100" 有 2 个尾随零，移除并返回整数 "512301"
     * \
     * 输入：num = "123"
     * 输出："123"
     * 解释：整数 "123" 不含尾随零，返回整数 "123"
     * \
     * @param args args
     */
    public static void main(String[] args) {
        RemoveTrailingZeros removeTrailingZeros = new RemoveTrailingZeros();
        String num = "51230100";
        System.out.println(removeTrailingZeros.removeTrailingZeros(num));
    }

    /**
     * 移除字符串中的尾随零
     *
     * @param num num
     * @return {@link String}
     */
    public String removeTrailingZeros(String num) {
        int right = num.length() - 1;
        while (num.charAt(right) == '0') {
            right--;
        }
        return num.substring(0, right + 1);
    }

}
